package com.qf.listener;

import com.event.util.EventHandler;
import com.event.util.EventType;
import com.qf.entity.Orders;
import com.qf.service.OrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

@Component
@EventType("orders_msg")
public class OrdersMsgHandler implements EventHandler<Map> {

    @Autowired
    private OrdersService ordersService;

    @Override
    public void msgHandler(Map map) {
        System.out.println("订单服务接收到下单请求：" + map);
        Integer uid = (Integer) map.get("uid");
        Integer gid = (Integer) map.get("gid");

        //生成订单创建
        Orders orders = new Orders()
                .setUid(uid)
                .setGid(gid)
                .setNumber(1)
                .setCreateTime(new Date())
                .setStatus(0);

        ordersService.save(orders);
    }
}
